<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui"
      xmlns:f="http://java.sun.com/jsf/core">

    <ui:composition template="layout.xhtml">
        <ui:define name="body">
            <style>
                .ui-button.ui-widget.ui-state-default.ui-corner-right.ui-button-icon-only {
                    border-radius: 0 4px 4px 0 !important;
                    height: auto !important;
                    position: absolute !important;
                    width: 29px !important;
                }
            </style>
            <div class="section">
                <h1>Dados da Venda</h1>
                <h:form id="formViewSale">

                    <p:growl id="msg" autoUpdate="true" life="3000"/>
                    <div class="clearfix container_24">
                        <div class="grid_3 right" style="margin-right: 30px;">
                            <p:splitButton value="Imprimir" >  
                                <p:menuitem value="Proposta" ajax="false"  update="@form" process="@form" 
                                            rendered="#{managerApproveSale.canGenerateContract(managerApproveSale.sale)}"
                                            title="Gerar Proposta"
                                            actionListener="#{managerApproveSale.reportsProposedContract(managerApproveSale.sale.id)}"
                                            icon="ui-icon-document"/>  
                                <p:menuitem value="Contrato" ajax="false"  update="@form" process="@form" 
                                            rendered="#{managerApproveSale.canGenerateContract(managerApproveSale.sale)}"
                                            title="Gerar Contrato"
                                            actionListener="#{managerApproveSale.reportContract(managerApproveSale.sale.id)}"
                                            icon="ui-icon-document"/>  
                                <p:menuitem value="Boleto" 
                                            icon="ui-icon-arrowrefresh-1-w"/>  
                                <p:separator />  
                            </p:splitButton>  
                        </div>
                        <div class="clear"/>
                        <p:panel header="Dados do Cliente" id="general_info"  toggleable="true">
                            <h:outputLabel value=" " styleClass="grid_4 labelCaption" />
                            <p:outputLabel value="#{managerApproveSale.customer.name}" styleClass="grid_14 headerLabel"  />
                            <div class="clear"/>
                            <p:outputLabel value="CPF: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.cpf}" styleClass="grid_10 labelValue" />
                            <h:outputLabel value="RG: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.rg}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="Profissão: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.profession}" styleClass="grid_10 labelValue" />
                            <h:outputLabel value="Naturalidade: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.nationality}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="Estado Civil: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.civilStatus.name}" styleClass="grid_10 labelValue" />
                            <h:outputLabel value="D. Nasc: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.dateOfBirth}" styleClass="grid_4 labelValue" >
                                <f:convertDateTime pattern="dd/MM/yyyy"/>  
                            </h:outputLabel>
                            <div class="clear"/>
                            <h:outputLabel value="Telefone: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.fixedPhone}" styleClass="grid_10 labelValue" />
                            <h:outputLabel value="Celular: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.celPhone}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="E-mail: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.customer.email}" styleClass="grid_10 labelValue" />
                            <div class="clear"/>

                            <p:dataTable id="tableAddView" var="address" value="#{managerApproveSale.customer.addresses}" 
                                         styleClass="grid_24"
                                         rowIndexVar="rowid"
                                         emptyMessage="Nenhum registro">  
                                <f:facet name="header">
                                    Endereço
                                </f:facet>
                                <p:column headerText="Rua" width="300">  
                                    <h:outputText value="#{address.patio}"/>
                                </p:column>  
                                <p:column headerText="Bairro">  
                                    <h:outputText value="#{address.district}"/>
                                </p:column>
                                <p:column headerText="Tipo">  
                                    <h:outputText value="#{address.typeAddress}"/>
                                </p:column>


                            </p:dataTable> 

                            <div class="clear"/>

                        </p:panel>

                        <p:panel header="Dados do Lote" toggleable="true">
                            <h:outputLabel value=" " styleClass="grid_4 labelCaption" />

                            <p:outputLabel value="#{managerApproveSale.sale.enterprise.name}" styleClass="grid_14 headerLabel"  />
                            <div class="clear"/>
                            <h:outputLabel value="Quadra: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.lot.block}" styleClass="grid_4 labelValue" />
                            <h:outputLabel value="Lote: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.lot.num}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="Número do Lote: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.lot.num}" styleClass="grid_4 labelValue" />
                            <h:outputLabel value="Dimensão: " styleClass="grid_4 labelCaption" />
                            <p:outputLabel value="#{managerApproveSale.dimensaoDoLote()}" styleClass="grid_4 labelValue"  />
                            <h:outputLabel value="Área: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.lot.area}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="Tipo: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.lot.typeLot.name}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                        </p:panel>

                        <p:panel header="Referências" toggleable="true">
                            <h:outputLabel value="Nome: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.nameOfReference1}" styleClass="grid_4 labelValue" />
                            <h:outputLabel value="Telefone: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.phoneOfReference1}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="Nome: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.nameOfReference2}" styleClass="grid_4 labelValue" />
                            <h:outputLabel value="Telefone: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.phoneOfReference2}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                        </p:panel>

                        <p:panel header="Testemunhas" toggleable="true">
                            <h:outputLabel value="Nome: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.nameOfTheWitness1}" styleClass="grid_4 labelValue" />
                            <h:outputLabel value="CPF: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.cpfOfTheWitness1}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <h:outputLabel value="Nome: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.nameOfTheWitness2}" styleClass="grid_4 labelValue" />
                            <h:outputLabel value="CPF: " styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.cpfOfTheWitness2}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                        </p:panel>

                        <p:panel header="Observações" toggleable="true">

                            <h:outputLabel value="#{managerApproveSale.sale.observation}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>

                        </p:panel>

                        <p:panel header="Valores Finais" toggleable="true">

                            <h:outputLabel value="Pagamento: " style="padding: 0 0.7em 0 0.5em" styleClass="grid_4 labelCaption" />
                            <h:outputLabel value="#{managerApproveSale.sale.paymentType.name}" styleClass="grid_4 labelValue" />
                            <div class="clear"/>
                            <p:panel styleClass="withoutBorder" visible="#{managerApproveSale.sale.paymentType.atSight}">
                                <h:outputLabel value="Valor á vista: " styleClass="grid_4 labelCaption" />
                                <h:outputLabel value="#{managerApproveSale.sale.lot.sees}" styleClass="grid_4 labelValue">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>
                                <div class="clear"/>
                                <h:outputLabel value="Desconto de: " styleClass="grid_4 labelCaption" />
                                <h:outputLabel value="#{managerApproveSale.sale.discount}" style="margin-left : 1%" styleClass="labelValue" />
                                <h:outputLabel value="#{managerApproveSale.sale.discountType.name}" styleClass="labelValue" />
                                <div class="clear"/>
                                <h:outputLabel value="Valor a pagar: " styleClass="grid_4 labelCaption"/>
                                <h:outputLabel value="#{managerApproveSale.sale.totalValue}" styleClass="grid_4 labelValue">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>

                                <div class="clear"/>
                            </p:panel>

                            <p:panel styleClass="withoutBorder" visible="#{managerApproveSale.sale.paymentType.installment}">
                                <h:outputLabel value="Entrada: " styleClass="grid_4 labelCaption"/>
                                <h:outputLabel value="#{managerApproveSale.sale.entryValue}" styleClass="grid_4 labelValue" >
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>
                                <div class="clear"/>
                                <h:outputLabel value="Parcelado em: " styleClass="grid_4 labelCaption" />
                                <h:outputLabel value="#{managerApproveSale.sale.quantityOfParcel} X " style="margin-left : 1%" styleClass="labelValue" />
                                <h:outputLabel value="#{managerApproveSale.sale.parcelValue}" styleClass="labelValue">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>

                            </p:panel>

                            <p:panel styleClass="withoutBorder" visible="#{managerApproveSale.sale.paymentType.custom}">
                                <h:outputLabel value="Valor da Entrada: " styleClass="grid_4 labelCaption" />
                                <h:outputLabel value="#{managerApproveSale.sale.entryValue}" styleClass="grid_4 labelValue">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>
                                <div class="clear"/>
                                <h:outputLabel value="Parcelado em: " styleClass="grid_4 labelCaption" />
                                <h:outputLabel value="#{managerApproveSale.sale.quantityOfParcel} X " styleClass="labelValue" />
                                <h:outputLabel value="#{managerApproveSale.sale.parcelValue}" styleClass="labelValue">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>
                                <h:outputLabel value="#{managerApproveSale.sale.interest eq '0' ? ' ( Juros '.concat(managerCreateSale.juros).concat(' )') : '' }" styleClass="labelValue" />
                                <div class="clear"/>
                                <h:outputLabel value="Valor Total: " styleClass="grid_4 labelCaption"/>    

                                <h:outputLabel value="#{managerApproveSale.sale.totalValue}" styleClass="grid_4 labelValue">
                                    <f:convertNumber pattern="#,###,##0.00"/>
                                </h:outputLabel>

                                <div class="clear"/>
                            </p:panel>

                        </p:panel>
                        <div class="buttonAction">
                            <p:commandButton value="Aprovar" 
                                             action="#{managerApproveSale.approve()}"
                                             update="msg"
                                             rendered="#{managerApproveSale.canApprove}"
                                             process="@form"
                                             icon="ui-icon-check" 
                                             styleClass="ui-priority-primary"/>
                            <p:commandButton value="Reprovar"
                                             rendered="#{managerApproveSale.canApprove}"
                                             styleClass="button-cancel-sale" onclick="dlgPending.show()" icon="ui-icon-closethick"  />

                            <p:button href="searchsale.xhtml" value="Voltar" icon="ui-icon-arrowreturnthick-1-w"  />
                        </div>

                    </div>

                    <p:dialog header="Reprovar Venda" widgetVar="dlgPending" modal="true" width="600" >
                        <div class="container_24">
                            <p:outputLabel value="Tipo de pendência: " style="float:left" />
                            <div class="grid_16">

                                <p:selectOneMenu styleClass="grid_24" value="#{managerApproveSale.pending.statusSale}">  
                                    <f:selectItems value="#{managerApproveSale.pendingType()}" />  
                                </p:selectOneMenu> 
                            </div>
                            <div class="clear"/>
                            <p:outputLabel value="Observações" styleClass="grid_4" />
                            <div class="clear"/>
                            <p:inputTextarea styleClass="grid_23" value="#{managerApproveSale.pending.description}" />
                            <div class="clear"/>

                            <div class="buttonAction">
                                <p:commandButton value="Salvar" 
                                                 action="#{managerApproveSale.reprove()}"
                                                 update="msg"
                                                 process="@form"
                                                 icon="ui-icon-disk" 
                                                 styleClass="ui-priority-primary"
                                                 oncomplete="dlgPending.hide()" />
                                <p:commandButton value="Cancelar" icon="ui-icon-close" onclick="dlgPending.hide()"  />
                            </div>
                        </div>

                    </p:dialog>
                </h:form>
            </div>
        </ui:define>
    </ui:composition>
</html>
